/*
		常用方法
*/

export default {
	/*
			字符串转换为数组
			str:被转换的字符串
			division:分隔符 默认已逗号分开
	*/
	strToArr(str, division) {
		division = division || ','
		str.split(',')
		return str
	},

	/*
			数组转换为数组字符串
			arr:被转换的数组
			division:分隔符 默认已逗号分开
	*/
	arrTostr(arr, division) {
		division = division || ','
		arr.split(',')
		return arr
	},

	/*
			数组转换为对象添加key
			arr:被转换的数组
			key:数组对象的key
	*/
	arrAddKey(arr, key) {
		let newArr = arr.map(item => ({
			key: item
		}))
		return newArr
	},

	/*
			两个字符串合并为数组
	*/
	strsMergeArr(str1, str2, str1Key, str2Key) {
		const str1Arr = str1.split(',')
		const str2Arr = str2.split(',')
		let newArr = str1Arr.map(item => ({
			str1Key: item
		}))
		newArr.forEach((value, index) => {
			value[str2Key] = conferenceFileNames[index]
		})
		return newArr
	},

	/*
			数组去重
	*/
	uniq(array) {
		var temp = []; //一个新的临时数组
		for (var i = 0; i < array.length; i++) {
			if (temp.indexOf(array[i]) == -1) {
				temp.push(array[i]);
			}
		}
		return temp;
	},
	/*
			数组去重方法二
	*/
	uniqSet(arr) {
		const uniqueArray = [...new Set(array)];
		return uniqueArray
	},

	/*
		秒数转换为时分秒	
	*/
	formatTime(time) {
		// 转换为式分秒
		let h = parseInt(time / 60 / 60 % 24)
		h = h < 10 ? '0' + h : h
		let m = parseInt(time / 60 % 60)
		m = m < 10 ? '0' + m : m
		let s = parseInt(time % 60)
		s = s < 10 ? '0' + s : s
		// 作为返回值返回
		if (h == '00') {
			return m + ':' + s
		}
		return h + ':' + m + ':' + s
	},

	/*
		秒数格式化分钟  四舍五入
	*/
	secondFormatMinute(time) {
		let minute = time / 60
		if (minute <= 1) {
		 return 1
		} else {
		 minute = Math.round(minute)
			return minute
		}
	},

	/*
		字符串数字末尾去0  例如1.00 => 1; 1.50 => 1.5
   */

	strNumberEndreMoveremove(strNumber) {
		if(typeof strNumber == 'number'){
			return strNumber
		}
		console.log(strNumber.substr(-2,1))
		if(strNumber.substr(-2,1) === '0'){
			strNumber = strNumber.replace('.00','')
		}else{
			strNumber = strNumber.substr(0, strNumber.length - 1)
		}
		return strNumber
	},


	formatSeconds(time) {
		var secondTime = parseInt(time); // 秒
		var minuteTime = 0; // 分
		var hourTime = 0; // 小时
		if (secondTime > 60) { //如果秒数大于60，将秒数转换成整数
			//获取分钟，除以60取整数，得到整数分钟
			minuteTime = parseInt(secondTime / 60);
			//获取秒数，秒数取佘，得到整数秒数
			secondTime = parseInt(secondTime % 60);
			//如果分钟大于60，将分钟转换成小时
			if (minuteTime > 60) {
				//获取小时，获取分钟除以60，得到整数小时
				hourTime = parseInt(minuteTime / 60);
				//获取小时后取佘的分，获取分钟除以60取佘的分
				minuteTime = parseInt(minuteTime % 60);
			}
		}
		var result = "" + parseInt(secondTime) + "秒";

		if (minuteTime > 0) {
			result = "" + parseInt(minuteTime) + "分" + result;
		}
		if (hourTime > 0) {
			result = "" + parseInt(hourTime) + "小时" + result;
		}
		return result;
	},


	/*
		判断数组是否相等
	*/

	arrCompare(arr1, arr2) {
		const result = arr1.length === arr2.length && arr1.every(a => arr2.some(b => a === b)) && arr2.every(_b => arr1
			.some(_a => _a === _b))
		return result
		// #ifdef MP-WEIXIN

		// #endif
	},


	/*
		解决富文本在小程序图片太大问题
	*/
	mpWieXinImg(html) {
		let mpWieXinImg = html
		mpWieXinImg = mpWieXinImg.replace(/\<img/gi, '<img class="rich-img" ');//正则给img标签增加class
		mpWieXinImg = mpWieXinImg.replace(/\<p/gi, '<P class="rich-p" '); //正则给p标签增加class
		// mpWieXinImg = mpWieXinImg.replace(/<img/g, "<img style='width:200rpx !important;'");
		// mpWieXinImg = mpWieXinImg.replace(/width\s*:\s*[0-9]+px/g, 'width:100%');
		//mpWieXinImg = mpWieXinImg.replace(/<([\/]?)(center)((:?\s*)(:?[^>]*)(:?\s*))>/g, '<$1div$3>');//替换center标签
		//mpWieXinImg = mpWieXinImg.replace(/style\s*?=\s*?([‘"])[\s\S]*?\1/ig, 'style="max-width:100%;height:auto;display: block;margin:auto"');
		return mpWieXinImg
	},

	/*
		小程序图片转base64
	*/
	mpWieXinFaceImgBase64(UserFaceImg) {
		return new Promise(function(resolve, reject) {
			uni.compressImage({
				src: UserFaceImg,
				quality: 80,
				success: (imageRes) => {
					console.log('压缩完成图片', imageRes.tempFilePath);
					// 获取类型
					let that = this
					uni.getImageInfo({
						src: imageRes.tempFilePath,
						success(imageInfo) {
							console.log('预览图片', imageInfo);
							// 转base64
							let userIdImgBase64 = wx.getFileSystemManager().readFileSync(
								imageRes.tempFilePath, 'base64');
							let base64Str = 'data:image/' + imageInfo.type + ';base64,' +
								userIdImgBase64
							console.log('base64图片', base64Str.substr(0, 50));
							resolve(base64Str)
							// return base64Str
						}
					})
				}
			})
		})


	},

	//获取域名参数 name参数名
	getQueryString(initialUrl, name)

	{


		let url = initialUrl;
		let requestParams = {};
		if (url.indexOf('?') !== -1) {
			let str = url.substr(url.indexOf('?') + 1); //截取?后面的内容作为字符串
			// console.log(str, '?后面的内容');
			let strs = str.split('&'); //将字符串内容以&分隔为一个数组
			// console.log(strs, '以&切割的数组');
			for (let i = 0; i < strs.length; i++) {
				requestParams[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1]);
				// 将数组元素中'='左边的内容作为对象的属性名，'='右边的内容作为对象对应属性的属性值
			}
		}
		// console.log(requestParams, '处理后的对象');
		return requestParams;


	},









}
